#pragma once

#include <QWidget>
#include <thread>
#include "d3d11.h"
#include "d3dcompiler.h"
#include "include/Monitor.h"

class ShowScreenWindow : public QWidget {
	Q_OBJECT

public:
	ShowScreenWindow(int x, int y, int width, int height, QWidget* parent = nullptr);
	// 禁用
	QPaintEngine* paintEngine() const { return nullptr; }
	void paintEvent(QPaintEvent* event);
	void resizeEvent(QResizeEvent* event);
	void start();
	bool stop();
	void swap();
	~ShowScreenWindow();

private:
	float m_bgColor[4] = { 1, 0.5, 0.5, 1 };
	ID3D11Device* m_d3dDevice = nullptr; // D3D设备
	ID3D11DeviceContext* m_d3dDeviceContext = nullptr; // D3D上下文
	IDXGISwapChain* m_swapChain = nullptr; // 交换链
	ID3D11Texture2D* m_depthStencilBuffer = nullptr; // 缓冲区
	ID3D11DepthStencilView* m_depthStencilView = nullptr;    //深度模板缓冲区窗口描述
	ID3D11RenderTargetView* m_renderTargetView = nullptr;    //绘制窗口描述
	ID3D11RasterizerState* m_rasterizeState = nullptr;       //状态
	D3D11_VIEWPORT m_viewport;       //我们所看到的视口
	std::vector<Monitor*>* m_monitor_v = nullptr;
	Monitor* m_showMonitor = nullptr;
	bool m_alive = false;
	std::thread* m_playThread = nullptr;
	
	void play();
	void initD3D();
	void resizeD3D();
	void updateD3D(ID3D11Texture2D* _target);
	void renderInit();
	void renderUpdate();
	void clearD3D();
};
